﻿CREATE TABLE MediaDefinitionAudits(
	MediaDefinitionAuditId INT IDENTITY(1,1) NOT NULL,
	MediaDefinitionId INT NOT NULL,
	UserId NVARCHAR(128) NOT NULL,
	AuditType SMALLINT NOT NULL,
	AuditDate DATETIME NOT NULL,
	Details VARCHAR(MAX) NOT NULL,
	CONSTRAINT PK_MediaDefinitionAudits PRIMARY KEY CLUSTERED 
	(
		MediaDefinitionAuditId ASC
	)
	WITH (
		PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON
	) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE MediaDefinitionAudits WITH CHECK ADD  CONSTRAINT FK_MediaDefinitionAudits_AspNetUsers FOREIGN KEY(UserId)
REFERENCES AspNetUsers (Id)
GO

ALTER TABLE MediaDefinitionAudits CHECK CONSTRAINT FK_MediaDefinitionAudits_AspNetUsers
GO

ALTER TABLE MediaDefinitionAudits WITH CHECK ADD  CONSTRAINT FK_MediaDefinitionAudits_MediaDefinition FOREIGN KEY(MediaDefinitionId)
REFERENCES MediaDefinition (MediaDefID)
GO

ALTER TABLE MediaDefinitionAudits CHECK CONSTRAINT FK_MediaDefinitionAudits_MediaDefinition
GO

CREATE NONCLUSTERED INDEX IX_MediaDefinitionAudits ON MediaDefinitionAudits
(
	MediaDefinitionId ASC
) WITH (
	PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF,
	ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON
) ON [PRIMARY]
GO